#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>

int main(void)
{
	int fd;
	int ret;
	struct input_event event;
	fd=open("/dev/input/event1",O_RDWR);
	if(fd<0)
	{
		perror("open");
		exit(1);
	}

	while(1)
	{
		ret=read(fd,&event,sizeof(struct input_event));
		if(ret<0)
		{
			perror("read");
			exit(1);
		}
		if(event.type==EV_KEY)
		{
			switch(event.code)
			{
			case KEY_POWER:
				if(event.value)
				{
					printf("power pressed\n");
				}
				else
				{
					printf("power up\n");
				}
				break;
			case KEY_VOLUMEDOWN:
				if(event.value)
				{
					printf("DOWN_KEY pressed\n");
				}
				else
				{
					printf("DOWN_KEY up\n");
				}
				break;
			case KEY_VOLUMEUP:
				if(event.value)
				{
					printf("UP_KEY pressed\n");
				}
				else
				{
					printf("UP_KEY up\n");
				}
				break;
			}
		}
	}

	close(fd);

	return 0;
}


